﻿using Anley.DomainDrivenDesign.Contract.Domain;
using Anley.DomainDrivenDesign.Contract.DomainAdapter;

namespace Anley.DomainDrivenDesign.Contract.Infrastructure;

/// <summary>
/// 仓储接口
/// </summary>
public interface IDbRepository
{
    /// <summary>
    /// 仓储上下文
    /// </summary>
    IDbRepositoryContext DbContext { get; }
}

/// <summary>
/// 仓储接口
/// </summary>
public interface IRepository<TEntity, TKey>
    : IDbRepository
    where TEntity : class, IEntity<TKey>
    where TKey : struct
{
    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="entity"></param>
    /// <param name="transaction"></param>
    /// <returns></returns>
    Task<int> InsertAsync(TEntity entity, IDbTransaction? transaction = null);

    /// <summary>
    /// 获取列表
    /// </summary>
    /// <param name="whereString"></param>
    /// <param name="queryParams"></param>
    /// <param name="transaction"></param>
    Task<IList<TEntity>> ListAsync(
        string? whereString = null,
        DynamicParameters? queryParams = null,
        IDbTransaction ? transaction = null);

    /// <summary>
    /// 获取列表
    /// </summary>
    /// <param name="whereCriteria"></param>
    /// <param name="queryParams"></param>
    /// <param name="transaction"></param>
    Task<IList<TEntity>> ListAsync(
        List<string> whereCriteria,
        DynamicParameters? queryParams = null, 
        IDbTransaction? transaction = null);

    /// <summary>
    /// 获取
    /// </summary>
    Task<TEntity> GetAsync(TKey id, IDbTransaction? transaction = null);

    /// <summary>
    /// 更新
    /// </summary>
    Task<bool> UpdateAsync(TEntity entity, IDbTransaction? transaction = null);

    /// <summary>
    /// 删除
    /// </summary>
    Task<bool> DeleteAsync(TEntity entity, IDbTransaction? transaction = null);

    /// <summary>
    /// 批量插入
    /// </summary>
    /// <param name="entities"></param>
    /// <param name="transaction"></param>
    Task BatchInsertAsync(List<TEntity> entities, IDbTransaction? transaction = null);

    /// <summary>
    /// 批量更新
    /// </summary>
    /// <param name="entities"></param>
    /// <param name="transaction"></param>
    Task BatchUpdateAsync(List<TEntity> entities, IDbTransaction? transaction = null);

    /// <summary>
    /// 获取分页列表
    /// </summary>
    /// <param name="whereString"></param>
    /// <param name="queryParams"></param>
    /// <param name="pageNumber"></param>
    /// <param name="pageSize"></param>
    /// <param name="selectFields"></param>
    /// <param name="sortFiled"></param>
    /// <param name="isAsc"></param>
    /// <param name="transaction"></param>
    PagedDto<TEntity> PagedList(
        string? whereString = null,
        DynamicParameters? queryParams = null,
        int? pageNumber = null,
        int? pageSize = null,
        string? selectFields = null,
        string? sortFiled = null,
        bool? isAsc = null,
        IDbTransaction? transaction = null);

    /// <summary>
    /// 获取分页列表
    /// </summary>
    /// <param name="whereCriteria"></param>
    /// <param name="queryParams"></param>
    /// <param name="pageNumber"></param>
    /// <param name="pageSize"></param>
    /// <param name="selectFields"></param>
    /// <param name="sortFiled"></param>
    /// <param name="isAsc"></param>
    /// <param name="transaction"></param>
    PagedDto<TEntity> PagedList(
        List<string> whereCriteria,
        DynamicParameters? queryParams = null,
        int? pageNumber = null,
        int? pageSize = null,
        string? selectFields = null,
        string? sortFiled = null,
        bool? isAsc = null,
        IDbTransaction? transaction = null);
}

/// <summary>
/// 仓储接口
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public interface IRepository<TEntity>
    : IRepository<TEntity, int>
    where TEntity : class, IEntity
{
}